package panel.viewSpots.navigationNew
{
	import assists.HtmlText;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import main.ClientConstants;
	
	public class PaoPaoSimPanel extends Sprite
	{
		private var _info:Object;
		private var _loader:ResourceLoader;
		private var _stage:Stage;
		private var _musicBtn:Sprite = new Sprite();
		private var _detailBtn:Sprite = new Sprite();
		private var _visitedBtn:Sprite = new Sprite();
		private var _id:int;
		private var _musicFunc:Function;
		private var _detailFunc:Function;
		private var _back:Sprite = new Sprite();
		public function PaoPaoSimPanel(loader:ResourceLoader,stage:Stage)
		{
			_loader = loader;
			_stage = stage;
			init();
		}
		
		private function init():void
		{
			_musicBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.paopaoMusicPng));
			generateSprite("语音导游",_musicBtn);
			_detailBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.paopaoDetailPng));
			generateSprite("详细",_detailBtn);
			_visitedBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.paopaoVisitPng));
		    generateSprite("我在这里",_visitedBtn);
			_back.addChild(_loader.uiManager.generateBmp(_loader.uiManager.paopaoBack));
			_back.scaleX = _back.scaleY = 1.5;
			_back.x = - _back.width * 0.5;
			_back.y = - _back.height * 0.5;
			
			
			_musicBtn.addEventListener(MouseEvent.CLICK,clickMusicHandler);
			_detailBtn.addEventListener(MouseEvent.CLICK,clickDetailHandler);
			
			this.addChild(_back);
			this.addChild(_musicBtn);
			this.addChild(_detailBtn);
			this.addChild(_visitedBtn);
		}
		
		public function changeLabel(value:String,id:int):void
		{
			_id = id;
			layout();
		}
		
		private function layout():void
		{
			_detailBtn.x = _back.x + (_back.width - _detailBtn.width) * 0.5;
			_detailBtn.y = _back.y + (_back.height - _detailBtn.height) * 0.5;
			_visitedBtn.y = _detailBtn.y;
			_visitedBtn.x = _back.x + _back.width  - _visitedBtn.width;
			_musicBtn.y = _detailBtn.y;
			_musicBtn.x = _back.x + _musicBtn.width * 0.25;
			
//			_back.graphics.clear();
//			_back.graphics.beginFill(0x00ccff);
//			_back.graphics.drawRoundRect(-10,-10,this.width + 20,this.height + 20,20,20);
//			_back.graphics.endFill();
		}
		
		public function set info(value:Object):void
		{
			_info = value;
			if(_info.mp3 == "")
			{
				_musicBtn.filters = [ClientConstants.GLOBAL_FILTER_GREY];
				_musicBtn.mouseEnabled = false;
			}else
			{
				_musicBtn.filters = [];
				_musicBtn.mouseEnabled = true;
			}
		}
		
		private function generateSprite(label:String,container:Sprite):void
		{
			var txt:TextField = new TextField();
			txt.mouseEnabled = false;
			txt.autoSize = "left";
			TextFieldUtils.setHtmlText(txt,HtmlText.formatSizeColor(label,0xffffff),true,true);
			txt.x = (container.width - txt.width) * 0.5;
			txt.y = container.height;
			
//			var spr:Shape = new Shape();
//			spr.graphics.beginFill(0);
//			spr.graphics.drawRect(txt.x,txt.y,txt.width,txt.height);
//			spr.graphics.endFill();
//			container.addChild(spr);
			container.addChild(txt);
		}
		
		public function get info():Object
		{
			return _info;
		}
		
		protected function clickDetailHandler(event:MouseEvent):void
		{
			_detailFunc(_info);
		}
		
		protected function clickMusicHandler(event:MouseEvent):void
		{
			_musicFunc(info.mp3,info.name);
		}
		
		public function set onMusicFunc(value:Function):void
		{
			_musicFunc = value;
		}
		
		public function set onDetailFunc(value:Function):void
		{
			_detailFunc = value;
		}
		
	}
}